home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 255_01 / gpbitblt.asm < prev    next >
Encoding:
Assembly Source File  |  1988-03-28  |  9.8 KB  |  314 lines

  1.           page   80,132
  2.           page
  3. ;
  4. ;       EGA Graphic Primitive for Microsoft C 3.0, Version 01APR86.
  5. ;       (C) 1986 by Kent Cedola, 2015 Meadow Lake Ct., Norfolk, VA, 23518
  6. ;
  7.  
  8. towork    equ    4
  9. fmwork    equ    6
  10.  
  11. towk      equ    -20
  12. tox       equ    -18
  13. toy       equ    -16
  14. tow       equ    -14
  15. toh       equ    -12
  16. fmwk      equ    -10
  17. fmx       equ    -8
  18. fmy       equ    -6
  19. fmw       equ    -4
  20. fmh       equ    -2
  21.  
  22. needed    equ    20                    ; Amount of temporary space needed
  23.  
  24. xorigin   equ    2
  25. yorigin   equ    4
  26. width     equ    6
  27. height    equ    8
  28. x         equ    10
  29. y         equ    12
  30. w         equ    14
  31. h         equ    16
  32. aspect1   equ    18
  33. aspect2   equ    20
  34.  
  35. dgroup    group  _data
  36.  
  37. _data     segment word public 'data'
  38.           assume ds:dgroup
  39.  
  40.           public _gdxmax,_gdxscale,_gdymax,_gdyscale
  41.  
  42. _gdxmax   dw     1024
  43. _gdxscale db     1024 dup(0)
  44. _gdymax   dw     1024
  45. _gdyscale db     1024 dup(0)
  46.  
  47. _data     ends
  48.  
  49. _text     segment byte public 'code'
  50.  
  51.           assume cs:_text,ds:dgroup
  52.           public _gpbitblt
  53.  
  54.           extrn  _xpcpywtg:near
  55. ;         extrn  _xpcpywtw:near,_xpcpywtg:near,_xpcpywtd:near,_xpcpywtp:near
  56. ;         extrn  _xpcpygtw:near,_xpcpygtg:near,_xpcpygtd:near,_xpcpygtp:near
  57. ;         extrn  _xpcpydtw:near,_xpcpydtg:near,_xpcpydtd:near,_xpcpydtp:near
  58.  
  59. _gpbitblt proc   near
  60.  
  61.           push   bp
  62.           mov    bp,sp
  63.           sub    sp,needed             ; Reserve space for temp. variables
  64.  
  65. fmparm:
  66.           mov    bx,[bp+fmwork]        ; Load pointer to 'from' work parameters
  67.           cmp    byte ptr[bx+1],0      ; Check for 'from' workspace
  68.           jne    fmarea                ; No, jump to 'from' workarea code
  69. fmspace:
  70.           mov    ax,[bx+x]             ; Compute 'from' true X coordinate
  71.           cmp    ax,[bx+width]         ;   ...
  72.           jae    wkerror               ;   ...
  73.           mov    [bp+fmx],ax           ;   ...
  74.  
  75.           mov    ax,[bx+y]             ; Compute 'from' true Y coordinate
  76.           cmp    ax,[bx+height]        ;   ...
  77.           jae    wkerror               ;   ...
  78.           mov    [bp+fmy],ax           ;   ...
  79.           jmp    short fmcont
  80. fmarea:
  81.           mov    ax,[bx+xorigin]       ; Compute 'from' true X coordinate
  82.           add    ax,[bx+x]             ;   ...
  83.           cmp    ax,[bx+width]         ;   ...
  84.           jae    wkerror               ;   ...
  85.           mov    [bp+fmx],ax           ;   ...
  86.  
  87.           mov    ax,[bx+yorigin]       ; Compute 'from' true Y coordinate
  88.           add    ax,[bx+y]             ;   ...
  89.           cmp    ax,[bx+height]        ;   ...
  90.           jae    wkerror               ;   ...
  91.           mov    [bp+fmy],ax           ;   ...
  92. fmcont:
  93.           mov    ax,[bx+width]         ; Compute 'from' true width
  94.           sub    ax,[bp+fmx]           ;   ...
  95.           cmp    ax,[bx+w]             ;   ...
  96.           jbe    fmar01                ;   ...
  97.           mov    ax,[bx+w]             ;   ...
  98. fmar01:                                ;   ...
  99.           mov    [bp+fmw],ax           ;   ...
  100.  
  101.           mov    ax,[bx+height]        ; Compute 'from' true height
  102.           sub    ax,[bp+fmy]           ;   ...
  103.           cmp    ax,[bx+h]             ;   ...
  104.           jbe    fmar02                ;   ...
  105.           mov    ax,[bx+h]             ;   ...
  106. fmar02:                                ;   ...
  107.           mov    [bp+fmh],ax           ;   ...
  108.           jmp    short toparm
  109. wkerror:
  110.           jmp    fullclip
  111. toparm:
  112.           mov    bx,[bp+towork]        ; Load pointer to 'to' work parameters
  113.           cmp    byte ptr [bx+1],0     ; Check for 'to' workspace
  114.           jne    toarea                ; No, jump to 'to' workarea code
  115. tospace:
  116.           mov    ax,[bx+x]             ; Compute 'to' true X coordinate
  117.           cmp    ax,[bx+width]         ;   ...
  118.           jae    wkerror               ;   ...
  119.           mov    [bp+tox],ax           ;   ...
  120.  
  121.           mov    ax,[bx+y]             ; Compute 'to' true Y coordinate
  122.           cmp    ax,[bx+height]        ;   ...
  123.           jae    wkerror               ;   ...
  124.           mov    [bp+toy],ax           ;   ...
  125.           jmp    short tocont
  126. toarea:
  127.           mov    ax,[bx+xorigin]       ; Compute 'to' true X coordinate
  128.           add    ax,[bx+x]             ;   ...
  129.           cmp    ax,[bx+width]         ;   ...
  130.           jae    wkerror               ;   ...
  131.           mov    [bp+tox],ax           ;   ...
  132.  
  133.           mov    ax,[bx+yorigin]       ; Compute 'to' true Y coordinate
  134.           add    ax,[bx+y]             ;   ...
  135.           cmp    ax,[bx+height]        ;   ...
  136.           jae    wkerror               ;   ...
  137.           mov    [bp+toy],ax           ;   ...
  138. tocont:
  139.           mov    ax,[bx+w]             ; If both width and height are zero then
  140.           or     ax,[bx+h]             ;   use 'from' width and height values
  141.           jne    toar01                ; No, jump over zero w,h code
  142.           mov    ax,[bp+fmw]           ; Copy 'from' width and height to 'to'
  143.           mov    [bp+tow],ax           ;   widht and height
  144.           mov    ax,[bp+fmh]           ;   ...
  145.           mov    [bp+toh],ax           ;   ...
  146.           jmp    short toar04          ;   ...
  147. toar01:
  148.           cmp    ax,0                  ; If the width is zero then compute it
  149.           jnz    toar02                ;   from the 'from' / 'to' height ratio
  150.           mov    ax,[bx+h]             ;   ...
  151.           mul    word ptr [bp+fmw]     ;   ...
  152.           div    word ptr [bp+fmh]     ;   ...
  153.           mul    word ptr [bx+aspect1] ;   ...
  154.           div    word ptr [bx+aspect2] ;   ...
  155. toar02:                                ;   ...
  156.           mov    [bp+tow],ax           ;   ...
  157.  
  158.           mov    ax,[bx+h]             ; If the height is zero then compute it
  159.           cmp    ax,0                  ;   from the 'from' / 'to' width ratio
  160.           jnz    toar03                ;   ...
  161.           mov    ax,[bx+w]             ;   ...
  162.           mul    word ptr [bp+fmh]     ;   ...
  163.           div    word ptr [bp+fmw]     ;   ...
  164.           mul    word ptr [bx+aspect2] ;   ...
  165.           div    word ptr [bx+aspect1] ;   ...
  166. toar03:                                ;   ...
  167.           mov    [bp+toh],ax           ;   ...
  168. toar04:
  169.           mov    ax,[bx+width]         ; Compute 'to' true width
  170.           sub    ax,[bp+tox]           ;   ...
  171.           cmp    ax,[bp+tow]           ;   ...
  172.           jge    toar05                ;   ...
  173.           mov    [bp+tow],ax           ;   ...
  174. toar05:
  175.           mov    ax,[bx+height]        ; Compute 'to' true height
  176.           sub    ax,[bp+toy]           ;   ...
  177.           cmp    ax,[bp+toh]           ;   ...
  178.           jge    toar06                ;   ...
  179.           mov    [bp+toh],ax           ;   ...
  180. toar06:
  181.  
  182. ;   Build slope array
  183.  
  184.           push   ds
  185.           pop    es
  186.  
  187.           pop    si
  188.           pop    di
  189.  
  190.           lea    di,dgroup:_gdxscale
  191.           mov    bx,[bp+fmw]
  192.           mov    dx,[bp+tow]
  193.           call   _gpslope
  194.  
  195.           lea    di,dgroup:_gdyscale
  196.           mov    bx,[bp+fmh]
  197.           mov    dx,[bp+toh]
  198.           call   _gpslope
  199.  
  200.           pop    di
  201.           pop    si
  202.  
  203. ;   Determine which routines to call for pixel copy.
  204.  
  205.           mov    bx,[bp+towork]
  206.           mov    [bp+towk],bx
  207.           mov    al,[bx]
  208.           shl    al,1
  209.           shl    al,1
  210.           mov    bx,[bp+fmwork]
  211.           mov    [bp+fmwk],bx
  212.           or     al,[bx]
  213.           xor    bh,bh
  214.           mov    bl,al
  215.           shl    bx,1
  216.           add    bx,offset _text:vectable
  217.           call   cs:[bx]
  218.           jmp    short theend
  219. fullclip:
  220.           mov    ax,-2
  221.           jmp    short done
  222. theend:
  223.           xor    ax,ax
  224. done:
  225.           mov    sp,bp                 ; Restore the stack
  226.           pop    bp
  227.           ret
  228.  
  229. vectable  dw     offset _text:_xpcpywtw
  230.           dw     offset _text:_xpcpywtg
  231.           dw     offset _text:_xpcpywtd
  232.           dw     offset _text:_xpcpywtp
  233.           dw     offset _text:_xpcpygtw
  234.           dw     offset _text:_xpcpygtg
  235.           dw     offset _text:_xpcpygtd
  236.           dw     offset _text:_xpcpygtp
  237.           dw     offset _text:_xpcpydtw
  238.           dw     offset _text:_xpcpydtg
  239.           dw     offset _text:_xpcpydtd
  240.           dw     offset _text:_xpcpydtp
  241.  
  242. _xpcpywtw:
  243. _xpcpywtd:
  244. _xpcpywtp:
  245. _xpcpygtw:
  246. _xpcpygtg:
  247. _xpcpygtd:
  248. _xpcpygtp:
  249. _xpcpydtw:
  250. _xpcpydtg:
  251. _xpcpydtd:
  252. _xpcpydtp:
  253.           ret
  254.  
  255. _gpbitblt endp
  256.  
  257. _gpslope  proc   near
  258.  
  259. ;         DI = address of slope
  260. ;         BX = X1
  261. ;         DX = X2
  262. ;         ES = DS
  263.  
  264.           cmp    dx,bx
  265.           je     line
  266.           ja     octant2
  267. octant1:
  268.           mov    cx,bx
  269.           dec    cx
  270.           mov    si,bx                 ; Error Register = -DX/2
  271.           shr    si,1                  ;   ...
  272.           neg    si                    ;   ...
  273. octant1L:
  274.           add    si,dx
  275.           js     octant1E
  276.           sub    si,bx
  277.           inc    al
  278. octant1E:
  279.           stosb
  280.           xor    al,al
  281.           loop   octant1L
  282.           ret
  283.  
  284. octant2:
  285.           mov    byte ptr [di],0
  286.           mov    cx,dx
  287.           dec    cx
  288.           mov    si,dx                 ; Error Register = -DY/2
  289. ;         shr    si,1                  ;   ...
  290.           neg    si                    ;   ...
  291. octant2L:
  292.           inc    byte ptr [di]
  293.           add    si,bx
  294.           js     octant2E
  295.           sub    si,dx
  296.           inc    di
  297.           mov    byte ptr [di],0
  298. octant2E:
  299.           loop   octant2L
  300.           inc    byte ptr [di]
  301.           ret
  302.  
  303. line:
  304.           mov    al,1
  305.           mov    cx,bx
  306.           rep stosb
  307.  
  308.           ret
  309.  
  310. _gpslope  endp
  311.  
  312. _text     ends
  313.           end
  314.